local skel = fk.CreateSkill {
  name = "emo__xiaoxin",
}

skel:addEffect(fk.AfterCardsMove, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(skel.name) and player:getHandcardNum() % 2 == 1 and player:getMaxCards() > 0 then
      for _, move in ipairs(data) do
        if move.to == player and move.toArea == Player.Hand then return true end
        if move.from == player and table.find(move.moveInfo, function(info) return info.fromArea == Player.Hand end) then
          return true
        end
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askToSkillInvoke(player, {skill_name = skel.name, prompt = "#emo__xiaoxin-minus"})
  end,
  on_use = function(self, event, target, player, data)
    player.room:addPlayerMark(player, MarkEnum.MinusMaxCardsInTurn)
    player:drawCards(1, skel.name)
  end,
})

skel:addEffect(fk.HpChanged, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(skel.name) and player == target and player.hp % 2 == 0 then
      return true
    end
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askToSkillInvoke(player, {skill_name = skel.name, prompt = "#emo__xiaoxin-add"})
  end,
  on_use = function(self, event, target, player, data)
    player.room:addPlayerMark(player, MarkEnum.AddMaxCards, 2)
    player:drawCards(2, skel.name)
  end,
})

Fk:loadTranslationTable{
  ["emo__xiaoxin"] = "嚣衅",
  [":emo__xiaoxin"] = "每当你手牌数变化为奇数时，你可以令本回合手牌上限-1以摸一张牌。每当你体力值变为偶数时，你可以令手牌上限+2并摸两张牌。",
  ["#emo__xiaoxin-minus"] = "嚣衅:你可以令手牌上限-1以摸一张牌",
  ["#emo__xiaoxin-add"] = "嚣衅:你可以令手牌上限+2并摸两张牌",
}

return skel
